﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RegExStudio.RegExStudioEventArgs;

namespace RegExStudio.UserControls
{
    public partial class CtrlMatch : CtrlGroup
    {
        private bool _warningVisible = false;
        /// <summary>
        /// Wenn es eine Exception beim RegEx erzeigen gab = true, sonst false
        /// Wenn true, wird das Control mit der Warnungfarbe eingefärbt
        /// </summary>
        public bool WarningVisible
        {
            get { return _warningVisible; }
            set
            {
                _warningVisible = value;
                if (_warningVisible)
                {
                    grpGroup.BackColor = Properties.Settings.Default.PatternExceptionColor;
                }
                else
                {
                    grpGroup.BackColor = this.BackColor;
                }
            }
        }

        /// <summary>
        /// Das gewünchte Match
        /// </summary>
        public int Match
        {
            get { return (int)numMatch.Value; }
            set { numMatch.Value = value; }
        }

        /// <summary>
        /// ctor
        /// </summary>
        public CtrlMatch()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Control wird geladen
        /// Eingabecontrol-Hintergrundfärbung aktivieren
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CtrlMatch_Load(object sender, EventArgs e)
        {
            numMatch.Enter += new EventHandler(Control_Enter);
            numMatch.Leave += new EventHandler(Control_Leave);
        }

        /// <summary>
        /// Im Spinedit hat sich was geändert
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void numMatch_ValueChanged(object sender, EventArgs e)
        {
            OnMatchChanged((int)numMatch.Value);
        }

        /// <summary>
        /// EventHandler für Änderung des Matches
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public delegate void MatchChangedEventHandler(object sender, MatchChangedEventArgs e);

        /// <summary>
        /// Event das ausgelöst wird, wenn gewählte Match geändert wurde
        /// </summary>
        public event MatchChangedEventHandler MatchChanged;

        /// <summary>
        /// Feuert das Event, wenn gewählte Match geändert wurde
        /// </summary>
        /// <param name="match"></param>
        protected virtual void OnMatchChanged(int match)
        {
            if (MatchChanged != null)
            {
                MatchChanged(this, new MatchChangedEventArgs(match));
            }
        }

    }
}
